
function openTestCasePage() {
    window.location.href = "/testCase/addTestCasePage";
}
function testCasePage() {
    var arrSelections=$("#dataTable").bootstrapTable("getSelections");
    if(arrSelections.length <=0){
        Ewin.alert("必须选择一条数据操作");
        return;
    }
    if(arrSelections.length >1){
        Ewin.alert("只能选择一个组件修改");
        return;
    }
    var id =arrSelections[0].id;
    window.location.href = "/testCase/testCasePage?interfaceId="+id+"&interfaceType=" + $("#interfaceType").val();
}
function query() {
    $("#dataTable").bootstrapTable("refresh")
}

function modifyTestCase() {
    var arrSelections=$("#dataTable").bootstrapTable("getSelections");
    if(arrSelections.length <=0){
        Ewin.alert("必须选择一条数据操作");
        return;
    }
    if(arrSelections.length >1){
        Ewin.alert("只能选择一个组件修改");
        return;
    }
    var id =arrSelections[0].id;
    window.location.href="/testCase/modifyTestCasePage?id="+id;
}
function deleteComponent() {
    var arrSelections=$("#dataTable").bootstrapTable("getSelections");
    if(arrSelections.length <=0){
        Ewin.alert("必须选择一条数据操作");
        return;
    }
    if(arrSelections.length >1){
        Ewin.alert("只能选择一个组件修改");
        return;
    }
    var id =arrSelections[0].id;
    var interfaceType=$("#interfaceType").val();
    var url ="/component/deleteComponent";
    Ewin.confirm({message: "确认要组件吗?如果删除那么组件下的用例也会被删除"}).on(function (e) {
        if (!e) {
            return;
        }
        $.ajax({
            url:url,
            method:"post",
            data:{
                id:id,
                interfaceType:interfaceType
            },success:function (result) {
                if(result.success){
                    $("#dataTable").bootstrapTable("refresh");
                }else {
                    Ewin.alert(result.msg);
                }
            }
        })
    });
}


function param(params) {
    var obj = {
        pageSize: params.limit,
        pageNum: (params.offset / params.limit) + 1,
        testCaseName: $("#testCaseName").val()
    };
    return obj;
}

$(function () {
    var interfaceUrl = "/testCase/testCaseList";
    $("#dataTable").bootstrapTable({
        url: interfaceUrl,
        method: "get",
        pageNumber: 1,
        pageSize: 10,
        pageList: [10, 20, 30, 40, 50],
        pagination: true,
        sidePagination: "server",
        cache: false,
        queryParams: param,
        height: 500,
        toolbar: "#toolbar",//这里面需要用到jquery的选择器
        paginationPreText: "上一页",
        paginationNextText: "下一页",
        striped: true,
        showRefresh: true,
        clickToSelect: true,
        sortable: false,
        sortOrder: "asc",
        columns: [
            {
                checkbox: true
            },
            {
                "title": "用例名称",
                "field": "testCaseName"
            },
            {
                "title": "创建人",
                "field": "userName"
            }
        ]
    })
})